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

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

d = A("d")
f = B("f")
j = B("j")
c = B("c")
h = B("h")
e = B("e")
n = A("n")
g = A("g")

d.x = n
f.q = g
j.q = g
c.q = g
h.q = d
e.q = d
n.x = g
g.x = n
assert g.x.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

d = A("d")
f = B("f")
j = B("j")
c = B("c")
h = B("h")
e = B("e")
n = A("n")
g = A("g")

d.x = n
f.q = g
j.q = g
c.q = g
h.q = d
e.q = d
n.x = g
g.x = n
assert g.x.x.x.x.x.x.x.x.txt == "g"