class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

d = A("d")
f = B("f")
c = B("c")
e = B("e")

d.q = e
f.y = d
c.y = d
e.y = d
assert c.y.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

d = A("d")
f = B("f")
c = B("c")
e = B("e")

d.q = e
f.y = d
c.y = d
e.y = d
assert c.y.q.y.q.txt == "e"