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

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

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

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

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

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

d.y = i
g.q = e
g.w = i
c.q = f
c.w = i
f.y = d
i.y = e
e.y = f
assert g.q.y.y.y.txt == "i"