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

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

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

f.o = k
c.p = k
d.p = f
e.p = k
g.p = f
k.o = f
assert d.p.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

f.o = k
c.p = k
d.p = f
e.p = k
g.p = f
k.o = f
assert d.p.o.o.o.txt == "k"